import random
from trend.models import Industry, KeywordTrend, PatentDistribution

def generate_test_data():
    """生成趋势分析测试数据"""
    
    # 清空现有数据
    Industry.objects.all().delete()
    
    # 创建产业数据
    industries = [
        {'id': 1, 'name': '大农业', 'description': '农业科技与现代化'},
        # ... 其他产业数据 ...
    ]
    
    for industry_data in industries:
        industry = Industry.objects.create(**industry_data)
        
        # 为每个产业生成关键词趋势
        keywords = generate_keywords_for_industry(industry.name)
        years = range(2019, 2024)
        
        for keyword in keywords:
            base_count = random.randint(80, 150)
            growth_rate = random.uniform(1.1, 1.3)
            
            for year in years:
                count = int(base_count * (growth_rate ** (year - 2019)))
                KeywordTrend.objects.create(
                    industry=industry,
                    keyword=keyword,
                    year=year,
                    count=count
                )
        
        # 生成专利分布数据
        generate_patent_data(industry)

def generate_keywords_for_industry(industry_name):
    """根据产业生成相关关键词"""
    industry_keywords = {
        '大数据': ['数据挖掘', '机器学习', '云计算', '数据安全', 'AI算法'],
        '人工智能': ['深度学习', '计算机视觉', '自然语言处理', '智能机器人', '知识图谱'],
        # ... 其他产业的关键词 ...
    }
    return industry_keywords.get(industry_name, ['技术创新', '产业升级', '智能化', '数字化'])

def generate_patent_data(industry):
    """生成专利分布数据"""
    institutions = ['清华大学', '中科院', '浙江大学', '北京大学', '华为技术', '上海交大']
    years = range(2019, 2024)
    
    for institution in institutions:
        base_count = random.randint(100, 200)
        for year in years:
            PatentDistribution.objects.create(
                industry=industry,
                institution=institution,
                year=year,
                patent_count=int(base_count * random.uniform(0.8, 1.2))
            )

if __name__ == '__main__':
    generate_test_data() 